#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
typedef unsigned long long ull;
typedef pair<i64, i64> PII;
typedef unordered_map<string, int> USI; 
typedef queue<string> QS;
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define lowbit(x) (x & -x)
#define _for(i, a, b) for (int i = a, I_MAX = b; i <= I_MAX; i++)
#define _rep(i, a, b) for (int i = a, I_MIN = b; i >= I_MIN; i--)
#define KS                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int rx[8] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int ry[8] = {1, 2, 2, 1, -1, -2, -2, -1};
const int MOD = 998244353;
const int INF = 0x3f3f3f3;
const int N = 2e5 + 10;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445;

void print(__int128 x)
{
    if (!x)
        return;
    if (x < 0)
        putchar('-'), x = -x;
    print(x / 10);
    putchar(x % 10 + '0');
}

i64 gcd(i64 a, i64 b)
{
    return b ? gcd(b, a % b) : a;
}

inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - 48;
        ch = getchar();
    }
    return x * f;
}

i64 inv(i64 a, i64 b)
{
    i64 res = 1;
    while (b > 0)
    {
        if (b % 2 == 1)
        {
            res = (res * a);
        }
        a = (a * a);
        b >>= 1;
    }
    return res;
}

void solve() 
{
     i64 h, w, m, ch = 0, cw = 0;
     cin >> h >> w >> m;
     vector<bool> H(h, false), W(w, false);
     vector<i64> op(m), x(m), y(m);
     for(int i = 0; i < m; i++)
     {
         cin >> op[i] >> x[i] >> y[i];
         x[i]--;
     }

     map<i64, i64> mp;

     for(int i = m - 1; i >= 0; i--)
     {
         if(op[i] == 1)
         {
             if(!H[x[i]])
             {
             ch++;
             i64 c = w - cw;
             mp[y[i]] = c + mp[y[i]];
             H[x[i]] = true;
             }

         }
         else 
         {   
             if(!W[x[i]])
             {
             cw++;
             mp[y[i]] += h - ch;
             W[x[i]] = true;
             }
         }
     }
     i64 sum = 1ll * w * h;
     for(auto it = mp.begin();it != mp.end();) 
     {
        long long k = (*it).first;
        cout << k <<endl;
        long long v = (*it).second;
         if(k != 0)
         {
            sum -= v;
         }
         if(k != 0 && v == 0)
         {
            it = mp.erase(it);
         }
         else it++;
     }
     mp[0] = sum;
     if(!sum) mp.erase(0);
     cout << mp.size() << endl;
     for(auto [k, v] : mp) cout << k << " " << v << endl;
}

int main()
{
    int t = 1;
    //cin>>t;
    mt19937 Rnd(time(0));
    while (t--)
    {
        solve();
    }
    return 0;
}